package tech.wisefin.track.session;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Comparator;
import java.util.Date;

public class SessionTrackView {
    private final SessionTrack track;
    private final SessionTrackFragment fragment;

    public SessionTrackView(SessionTrack track) {
        this.track = track;
        this.fragment = track
                .getFragments()
                .stream()
                .max(Comparator.comparing(SessionTrackFragment::getCreatedAt))
                .orElse(new SessionTrackFragment());
    }

    @JsonProperty("id")
    public String getId() {
        return this.track.getId();
    }

    @JsonProperty("session")
    public String getSession() {
        return this.track.getSession();
    }

    @JsonProperty("fragment_count")
    public int getFragmentCount() {
        return this.track.getFragments().size();
    }

    public Date getTimestamp() {
        return this.fragment.getCreatedAt();
    }
}
